﻿@model AllSettingsListModel
@using System.Linq;
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form  layui-form-pane  layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="Name" id="Name" placeholder="请输入名称" autocomplete="off">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">值</label>
                    <div class="layui-input-inline">
                        <input class="layui-input" name="Value" id="Value" placeholder="请输入值" autocomplete="off">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="LAY-app-contlist-search">搜索</button>
                    <button class="layui-btn  layui-btn-normal layuiadmin-btn-tags" data-type="add">添加</button>
                </div>
            </div>
        </div>
        <div class="layui-card-body">
            <table id="LAY-allsettings-list" lay-data="" lay-filter="LAY-allsettings-list"></table>
            <script type="text/html" id="layuiadmin-app-cont-tagsbar">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script>
    layui.use(['index','table','form'], function () {

        var table = layui.table
            ,form = layui.form;
        //设置管理
        table.render({
            elem: '#LAY-allsettings-list'
            , id: 'LAY-allsettings-list'
            , method: 'post'
            , url: '@Html.Raw(Url.Action("AllSettings", "Setting"))' //模拟接口
            , page: true //开启分页
            , even: true
            , limit: 30
            , limits: [15,30,50,100]
            , cols: [[
                { type: 'numbers', fixed: 'left' }
                , { field: 'Name', title: '名称', edit: 'text', minWidth: 100 }
                , { field: 'Value', title: '值', edit: 'text',  minWidth: 100 }
                , { title: '操作', width: 150, align: 'center', fixed: 'right', toolbar: '#layuiadmin-app-cont-tagsbar' }
            ]]
            , text: { none: '一条数据也没有^_^' }
        });

        //监听工具条
        table.on('tool(LAY-allsettings-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Html.Raw(Url.Action("SettingDelete"))', { id: obj.data.Id });
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                var tr = $(obj.tr);
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("AllSettingsEdit")?id=' + data.Id
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['500px', '450px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        });
        //监听单元格编辑
        table.on('edit(LAY-allsettings-list)', function (obj) {
            var value = obj.value //得到修改后的值
                , data = obj.data //得到所在行所有键值
                , field = obj.field; //得到字段
            $.post('@Html.Raw(Url.Action("SettingUpdate"))', { id: data.Id,name:obj.data.Name,value:obj.data.Value});
        });

        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            console.log(data)
            var field = data.field;
            //执行重载
            table.reload('LAY-allsettings-list', {
                url:'@Html.Raw(Url.Action("AllSettings"))'
                ,where: field
            });
        });

        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("AllSettingsEdit")'
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['500px', '300px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
